package com.liruo.enumconverter.autoconfigure.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.type.AnnotatedTypeMetadata;

class OnNotPropertyValueCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        MergedAnnotations annotations = metadata.getAnnotations();
        MergedAnnotation<ConditionalOnNOProperty> conditional = annotations.get(ConditionalOnNOProperty.class);
        String prefix = conditional.getString("prefix");
        String notEqualProperties = conditional.getString("notEqualProperties");

        String property = context.getEnvironment().getProperty(prefix);

        return property == null || !property.equalsIgnoreCase(notEqualProperties);
    }
}